unit Class_Rend;

interface
uses
  Classes,SysUtils,ElTree,Class_Unit,Class_Dept;

type
  TRend=class(TObject)
  public
    //Unit
    class procedure RendTreeUnit(AStrsUnit:TStringList;ATreeUnit:TEltree);
    class function  FindPrevUnit(APrevLink:string;ATreeUnit:TElTree):TElTreeItem;
    //Dept
    class procedure RendTreeDept(AStrsDept:TStringList;ATreeDept:TElTree);
    class function  FindPrevDept(APrevLink:string;ATreeDept:TElTree):TElTreeItem;


  end;

implementation

uses
  Dialogs;

{ TRend }

class function TRend.FindPrevDept(APrevLink: string;
  ATreeDept: TElTree): TElTreeItem;
var
  I:Integer;
  DeptA:TDept;
  ItemA:TElTreeItem;  
begin
  Result:=nil;
  if APrevLink='' then Exit;
  with ATreeDept do
  begin
    Items.BeginUpdate;
    for I:=0 to Items.Count-1 do
    begin
      ItemA:=Items.Item[I];
      DeptA:=TDept(ItemA.Data);
      if DeptA.DeptLink=APrevLink then
      begin
        Result:=ItemA;
        Break;
      end;  
    end;  
    Items.EndUpdate;
  end;  
end;

class function TRend.FindPrevUnit(APrevLink: string;
  ATreeUnit: TElTree): TElTreeItem;
var
  I:Integer;
  UnitA:TUnit;
  ItemA:TElTreeItem;  
begin
  Result:=nil;
  if APrevLink='' then Exit;
  with ATreeUnit do
  begin
    Items.BeginUpdate;
    for I:=0 to Items.Count-1 do
    begin
      ItemA:=Items.Item[I];
      UnitA:=TUnit(ItemA.Data);
      if UnitA.UnitLink=APrevLink then
      begin
        Result:=ItemA;
        Break;
      end;  
    end;  
    Items.EndUpdate;
  end;  
end;

class procedure TRend.RendTreeDept(AStrsDept: TStringList;
  ATreeDept: TElTree);
var
  I    :Integer;
  DeptA:TDept;
  ItemA:TElTreeItem;
  ItemB:TElTreeItem;
begin
   with ATreeDept do
   begin
     Items.Clear;
     ShowHint:=True;
     if (AStrsDept=nil) or (AStrsDept.Count=0) then Exit;
     Items.BeginUpdate;
     for I:=0 to AStrsDept.Count-1 do
     begin
       DeptA:=TDept(AStrsDept.Objects[I]);
       ItemA:=FindPrevDept(DeptA.DeptPrev,ATreeDept);
       ItemB:=ATreeDept.Items.AddChildObject(ItemA,DeptA.DeptCode+'  '+DeptA.DeptName,DeptA);
       ItemB.Hint:=DeptA.DeptName;
     end;
     Items.EndUpdate;
   end;
end;

class procedure TRend.RendTreeUnit(AStrsUnit: TStringList;
  ATreeUnit: TEltree);
var
  I    :Integer;
  UnitA:TUnit;
  ItemA:TElTreeItem;
  ItemB:TElTreeItem;
begin
   with ATreeUnit do
   begin
     Items.Clear;
     ShowHint:=True;
     if (AStrsUnit=nil) or (AStrsUnit.Count=0) then Exit;
     Items.BeginUpdate;
     for I:=0 to AStrsUnit.Count-1 do
     begin
       UnitA:=TUnit(AStrsUnit.Objects[I]);
       ItemA:=FindPrevUnit(UnitA.UnitPrev,ATreeUnit);
       ItemB:=ATreeUnit.Items.AddChildObject(ItemA,UnitA.UnitCode+'  '+UnitA.UnitName,UnitA);
       ItemB.Hint:=UnitA.UnitName;
     end;
     Items.EndUpdate;
   end;
end;

end.
